package club.ruanx.solr.repository;

import club.ruanx.solr.entity.SolrMovie;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.SolrCrudRepository;

/**
 * @author 阮胜
 * @date 2018/11/23 14:32
 */
public interface SolrMovieRepository extends SolrCrudRepository<SolrMovie, String> {


    Page<SolrMovie> findByNameLike(String movieName, Pageable pageable);

    /**
     * 模糊查询
     *
     * @param keywords 关键词
     * @param distance 距离(比如 无双~1 ,距离单位为1, 会查询"无"开头的)
     * @param pageable 分页参数
     * @return
     */
    @Query("movie_keywords:?0~?1")
    Page<SolrMovie> findByKeywordsWithDistance(String keywords, int distance, Pageable pageable);

    @Query("movie_keywords:?0~")
    Page<SolrMovie> findByKeywordsWithNullDistance(String keywords, Pageable pageable);

    @Query("movie_keywords:?0")
    Page<SolrMovie> findByKeywords(String keywords, Pageable pageable);
}
